package com.huanqiu.mylib.util;

import java.util.Random;

public final class MiscUtil {

    private static final Random sRandom = new Random();

    // 生成一段随机字符串
    public static String randomStr(int length) {
        final String dict = "0123456789abcdefghijklmnopqrstuvwxyz"; // 36
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(dict.charAt(sRandom.nextInt(dict.length())));
        }
        return sb.toString();
    }

    // 生成一段随机数
    public static String randomNum(int length) {
        final String dict = "0123456789"; // 10
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(dict.charAt(sRandom.nextInt(dict.length())));
        }
        return sb.toString();
    }

}
